import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/countryValue/index',
  },
  {
    path: '/home',
    component: () => import('@/views/home/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },



  {
    path: '/example',
    component: Layout,
    redirect: '/example/index',
    name: 'Example',
    meta: { title: 'Example', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/table/index'),

      },
    ]
  },
  {
    path: '/pageIndex',
    component: Layout,
    redirect: '/pageIndex/index',
    name: 'index',
    meta: { title: '首页', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/index',
        name: 'pageIndex',
        component: () => import('@/views/index/index'),
        meta: { title: '首页', icon: 'table' }
      },
    ]
  },

  {
    path: '/countryValue',
    component: Layout,
    alwaysShow: false,
    meta: {
      title: '全国指数',
      icon: 'nested'
    },
    children: [
      {
        path: 'index',
        name: 'countryValue',
        component: () => import('@/views/countryValue/index'),
        meta: { title: '全国指数', icon: 'form' }
      }
    ]
  },

  {
    path: '/cityValue',
    component: Layout,
    redirect: '/cityValue/city',
    name: 'cityValue',
    meta: {
      title: '城市指数',
      icon: 'nested'
    },
    children: [
      {
        path: 'cityIndex',
        component: () => import('@/views/cityValue/index'),
        name: 'cityIndex',
        meta: { title: '城市数据中心' },
      },
      {
        path: 'cityTrend',
        component: () => import('@/views/cityValue/cityTrend'),
        name: 'cityTrend',
        meta: { title: '城市走势' },
      },
      {
        path: 'region',
        component: () => import('@/views/cityValue/region'),
        name: 'region',
        meta: { title: '行政区走势' }
      },
      {
        path: 'cityPrivate',
        component: () => import('@/views/cityValue/cityPrivate'),
        name: 'cityPrivate',
        meta: { title: '城市定制' }
      }
    ]
  },

  {
    path: '/regionValue',
    component: Layout,
    redirect: '/regionValue/area',
    name: 'regionValue',
    alwaysShow: true,
    meta: {
      title: '行政区指数',
      icon: 'nested'
    },
    children: [
      {
        path: 'area',
        component: () => import('@/views/region/area.vue'),
        name: 'area',
        meta: { title: '片区走势' }
      }
    ]
  },
  {
    path: '/manager',
    component: Layout,
    redirect: '/manager/user',
    name: 'manager',
    alwaysShow: true,
    meta: {
      title: '系统管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/manager/user.vue'),
        name: 'user',
        meta: { title: '用户管理' }
      },
      {
        path: 'menu',
        component: () => import('@/views/manager/menu.vue'),
        name: 'user',
        meta: { title: '菜单管理' }
      },
      {
        path: 'role',
        component: () => import('@/views/manager/role.vue'),
        name: 'user',
        meta: { title: '角色管理' }
      },
      {
        path: 'tips',
        component: () => import('@/views/manager/tips.vue'),
        name: 'user',
        meta: { title: '公告' }
      }
    ]
  },
  {
    path: '/down',
    component: Layout,
    redirect: '/manager/user',
    name: 'manager',
    alwaysShow: false,
    meta: {
      title: '文件下载',
      icon: 'nested'
    },
    children: [
      {
        path: 'fileUpload',
        component: () => import('@/views/manager/fileUpload.vue'),
        name: 'user',
        meta: { title: '文件管理' }
      },
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
